package com.andnnl.service.base;

import com.andnnl.dao.base.EmasUcinfoDao;
import com.andnnl.pojo.base.EmasUcinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chenss on 2019/5/14.
 */
@Service
public class EmasUcinfoService {

    @Autowired
    EmasUcinfoDao emasUcinfoDao;

    public List<EmasUcinfo> getList() {

        Map<String, Object> paras = new HashMap<>();
//        paras.put("uid", "andnnl");
        return emasUcinfoDao.getSQLManager().select("emasUcinfo.sample", EmasUcinfo.class, paras, 1L, 10L);
    }

    public void insert(String username){
        EmasUcinfo query;
//        插入返回ID
        query = new EmasUcinfo();
        query.setUsername(username);
        query.setUid(username);
        query.setLevels(0);
        query.setRtnum(0);
        query.setRtcount(0);
        query.setFee(new BigDecimal("0"));
        query.setFei(0);
        query.setIsagent(0);
        query.setShownum(0);
        query.setShowcount(0);
        query.setIsagentop(0);
        query.setFailnum(0);
        query.setFailcount(0);
        query.setPrice(new BigDecimal("0"));
        int rs=emasUcinfoDao.getSQLManager().insert(query,true);
        System.out.println(query);
    }
    /**
     * 根据name返回用户Bean
     *
     * @param userName
     * @return
     */
    public EmasUcinfo getUser(String userName) {

        EmasUcinfo bean = new EmasUcinfo();
        bean.setUid(userName);
        List<EmasUcinfo> list = emasUcinfoDao.getSQLManager().template(bean);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }



    public void del(String username) {

        int rs=emasUcinfoDao.deleteByUsername(username);
    }

    public int updateByTmpId(EmasUcinfo emasUcinfo) {
        int rs=emasUcinfoDao.updateTemplateById(emasUcinfo);
        return rs;
    }
}
